/**
 * The class Point represents a point using two double data type variables, signifying the x coordinate and the y coordinate
 * @author Michael Fildstein, ID: 309161594     
 * @author Tomer Ben Rachel ID: 021982475     
 * 
 *
 */



public class Point {

	private double x;
	private double y;

/**
 * Constructor that creates a new point with the values 0.0,0.0
 */
	
public Point(){
	this(0.0,0.0);
	}


/**
 * Constructor that creates a new point with two variables of double data type which are received from the user
 * @param x1 a double data type representing the x coordinate
 * @param y1 a double data type representing the y coordinate
 */

public Point(double x1, double y1){
	x=x1;
	y=y1;
   }


/**
 * Copy Constructor that creates a new point using another point which is received from the user
 * @param other a Point data type representing the point to be copied
 */


public Point(Point other){
	if(other!=null && other instanceof Point)
		{x=other.x;
		 y=other.y;
		}
	}

/**
 * A getter method which returns the x coordinate of the current point
 * @return a double data type representing the x coordinate
 * 
 */

public double getX(){
	return x;
	}

/**
 * A getter method which returns the y coordinate of the current point
 * @return a double data type representing the y coordinate
 * 
 */


public double getY(){
	return y;
	}


/**
 * The boolean method equals compares two points to see if they are the same point
 * @param other a Point data type representing the point to be compared to
 * @throws Runtime exception if the point value is null
 * @return a boolean data type which indicates of the points are equal(meaning they are the same coordinate) or not
 */

public boolean equals(Point other){
	if(other!=null && other instanceof Point) 
		{return (x==other.x && y==other.y);
		}
	else throw new RuntimeException("Point value is null");
	}




/**
 * The method toString returns a string representing the point by it's coordinates
 * @return a string data type representing the point by it's coordinates
 */

public String toString(){
	String ans = "(" + x + " , " + y + ")";
	return ans;
	}



/**
 * The method translate receives a Point data type and adds it's coordinates to the current point
 * @param p a Point data type representing the point to be added to the current point
 * @throws Runtime exception if the point value is null
 */


public void translate(Point p){
	if(p!=null)
		{x=x+p.x;
		 y=y+p.y;
		}
	}



/**
 * The method distance receives a point from the user and calculates the distance between that point and the current one
 * @param p a Point data type representing the point received from the user
 * @throws Runtime exception if the point value is null
 * @return a double data type representing the distance between the two points
 */

public double distance(Point p){
	if(p!=null)
		{return Math.sqrt(Math.pow(x-p.x,2) + Math.pow(y-p.y,2));
		}
	else throw new RuntimeException("Point value is null");
	}
	
}